]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
croco: Prefer using g_clear_* macros
authorBilal Elmoussaoui <belmouss@redhat.com>
Wed, 15 Apr 2026 07:31:20 +0000 (09:31 +0200)
committerBilal Elmoussaoui <belmouss@redhat.com>
Wed, 15 Apr 2026 07:31:20 +0000 (09:31 +0200)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4176>

src/st/croco/cr-attr-sel.c
src/st/croco/cr-declaration.c
src/st/croco/cr-doc-handler.c
src/st/croco/cr-fonts.c
src/st/croco/cr-input.c
src/st/croco/cr-om-parser.c
src/st/croco/cr-parser.c
src/st/croco/cr-selector.c
src/st/croco/cr-statement.c
src/st/croco/cr-tknzr.c

index fc8e6ef8094bccce6652ef66cf1b57c05c9ded44..e641e4ecb84359148634a078ee5be0e5122e46ff 100644 (file)
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
- * 
+ *
  * See COPYRIGHTS file for copyrights information.
  */
 
@@ -62,11 +62,11 @@ cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
 {
         CRAttrSel *cur_sel = NULL;
 
-        g_return_val_if_fail (a_this && a_attr_sel, 
+        g_return_val_if_fail (a_this && a_attr_sel,
                               CR_BAD_PARAM_ERROR);
 
-        for (cur_sel = a_this; 
-             cur_sel->next; 
+        for (cur_sel = a_this;
+             cur_sel->next;
              cur_sel = cur_sel->next) ;
 
         cur_sel->next = a_attr_sel;
@@ -85,10 +85,10 @@ cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
  *Returns CR_OK upon successful completion, an error code otherwise.
  */
 enum CRStatus
-cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this, 
+cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this,
                               CRAttrSel * a_attr_sel)
 {
-        g_return_val_if_fail (a_this && a_attr_sel, 
+        g_return_val_if_fail (a_this && a_attr_sel,
                               CR_BAD_PARAM_ERROR);
 
         a_attr_sel->next = a_this;
@@ -123,7 +123,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this)
                 if (cur->name) {
                         guchar *name = NULL;
 
-                        name = (guchar *) g_strndup (cur->name->stryng->str, 
+                        name = (guchar *) g_strndup (cur->name->stryng->str,
                                           cur->name->stryng->len);
                         if (name) {
                                 g_string_append (str_buf, (const gchar *) name);
@@ -135,7 +135,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this)
                 if (cur->value) {
                         guchar *value = NULL;
 
-                        value = (guchar *) g_strndup (cur->value->stryng->str, 
+                        value = (guchar *) g_strndup (cur->value->stryng->str,
                                            cur->value->stryng->len);
                         if (value) {
                                 switch (cur->match_way) {
@@ -226,9 +226,6 @@ cr_attr_sel_destroy (CRAttrSel * a_this)
                 a_this->next = NULL;
         }
 
-        if (a_this) {
-                g_free (a_this);
-                a_this = NULL;
-        }
+        g_clear_pointer (&a_this, g_free);
 }
 
index 6c70128a256de94f1eac59ab50a181e16bdfb078..1917f62e701868a8e24297dbe4ade59ea50c8c1c 100644 (file)
@@ -548,10 +548,7 @@ cr_declaration_to_string (CRDeclaration const * a_this, gulong a_indent)
                 g_string_free (stringue, TRUE);
                 stringue = NULL;
         }
-        if (str) {
-                g_free (str);
-                str = NULL;
-        }
+        g_clear_pointer (&str, g_free);
 
         return result;
 }
index b0ef13c0726cda836222454dc13373088b9b193a..0806af828b055eba5182aecd7e2204799bb5d4ae 100644 (file)
@@ -251,10 +251,7 @@ cr_doc_handler_destroy (CRDocHandler * a_this)
 {
         g_return_if_fail (a_this);
 
-        if (a_this->priv) {
-                g_free (a_this->priv);
-                a_this->priv = NULL;
-        }
+        g_clear_pointer (&a_this->priv, g_free);
         g_free (a_this);
 }
 
index a64ffc045b3e943acd6988fe611725fcb375673f..da16cf8839458bd06fc0563f8ad0e70837db3158 100644 (file)
@@ -229,10 +229,7 @@ cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name)
                 return CR_BAD_PARAM_ERROR;
         }
 
-        if (a_this->name) {
-                g_free (a_this->name);
-                a_this->name = NULL;
-        }
+        g_clear_pointer (&a_this->name, g_free);
 
         a_this->name = a_name;
         return CR_OK;
@@ -303,10 +300,7 @@ cr_font_family_destroy (CRFontFamily * a_this)
         for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
 
         for (; cur_ff; cur_ff = cur_ff->prev) {
-                if (a_this->name) {
-                        g_free (a_this->name);
-                        a_this->name = NULL;
-                }
+                g_clear_pointer (&a_this->name, g_free);
 
                 if (cur_ff->next) {
                         g_free (cur_ff->next);
index 170d8d971667b557eeee1bb3be159a6218f61c63..9a6983bbdd00bc613dfd87da13c73e579a3548cc 100644 (file)
@@ -263,10 +263,7 @@ cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc)
                 file_ptr = NULL;
         }
 
-        if (buf) {
-                g_free (buf);
-                buf = NULL;
-        }
+        g_clear_pointer (&buf, g_free);
 
         return result;
 }
index 90f710621911bf9b41e69759786a69afa7cf6d25..e9fdcd27b2a54c01d1cbcbce99bce64d2c6428ef 100644 (file)
@@ -727,10 +727,7 @@ property (CRDocHandler * a_this,
         return;
 
       error:
-        if (str) {
-                g_free (str);
-                str = NULL;
-        }
+        g_clear_pointer (&str, g_free);
 
         if (decl) {
                 cr_declaration_destroy (decl);
@@ -1135,8 +1132,5 @@ cr_om_parser_destroy (CROMParser * a_this)
                 PRIVATE (a_this) = NULL;
         }
 
-        if (a_this) {
-                g_free (a_this);
-                a_this = NULL;
-        }
+        g_clear_pointer (&a_this, g_free);
 }
index 3f1b36c9a27b9c1adc98c4a435d05a885f999352..4abf3b9074a20abf4e35dddd98ec59198fb5fa9c 100644 (file)
@@ -501,10 +501,7 @@ cr_parser_error_destroy (CRParserError * a_this)
 {
         g_return_if_fail (a_this);
 
-        if (a_this->msg) {
-                g_free (a_this->msg);
-                a_this->msg = NULL;
-        }
+        g_clear_pointer (&a_this->msg, g_free);
 
         g_free (a_this);
 }
@@ -603,10 +600,7 @@ cr_parser_clear_errors (CRParser * a_this)
                 }
         }
 
-        if (PRIVATE (a_this)->err_stack) {
-                g_list_free (PRIVATE (a_this)->err_stack);
-                PRIVATE (a_this)->err_stack = NULL;
-        }
+        g_clear_pointer (&PRIVATE (a_this)->err_stack, g_list_free);
 
         return CR_OK;
 }
@@ -4524,8 +4518,5 @@ cr_parser_destroy (CRParser * a_this)
                 PRIVATE (a_this) = NULL;
         }
 
-        if (a_this) {
-                g_free (a_this);
-                a_this = NULL;  /*useless. Just for the sake of coherence */
-        }
+        g_clear_pointer (&a_this, g_free);
 }
index 37f5abc54c1470d7db2ca17ec9589d19acb495f2..179391194436a0541c699fd1dd4dae7cb88ccb68 100644 (file)
@@ -273,19 +273,13 @@ cr_selector_destroy (CRSelector * a_this)
 
         /*walk backward the list and free each "next element" */
         for (cur = cur->prev; cur && cur->prev; cur = cur->prev) {
-                if (cur->next) {
-                        g_free (cur->next);
-                        cur->next = NULL;
-                }
+                g_clear_pointer (&cur->next, g_free);
         }
 
         if (!cur)
                 return;
 
-        if (cur->next) {
-                g_free (cur->next);
-                cur->next = NULL;
-        }
+        g_clear_pointer (&cur->next, g_free);
 
         g_free (cur);
 }
index eaeb49f3514f30eb67d4650c485efddd0c7f7d46..7783545164fbb70132f43bececf8170fb9051ade 100644 (file)
@@ -625,10 +625,7 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent)
         g_string_append (stringue, "}");
         result = g_string_free (stringue, FALSE);
 
-        if (tmp_str) {
-                g_free (tmp_str);
-                tmp_str = NULL;
-        }
+        g_clear_pointer (&tmp_str, g_free);
         return result;
 }
 
@@ -715,10 +712,7 @@ cr_statement_charset_to_string (CRStatement const *a_this,
                 cr_utils_dump_n_chars2 (' ', stringue, a_indent);
                 g_string_append_printf (stringue, 
                                         "@charset \"%s\" ;", str);
-                if (str) {
-                        g_free (str);
-                        str = NULL;
-                }
+                g_clear_pointer (&str, g_free);
         }
         if (stringue) {
                 str = g_string_free (stringue, FALSE);
@@ -2764,20 +2758,14 @@ cr_statement_destroy (CRStatement * a_this)
 
         /*walk backward and free next element */
         for (cur = cur->prev; cur && cur->prev; cur = cur->prev) {
-                if (cur->next) {
-                        g_free (cur->next);
-                        cur->next = NULL;
-                }
+                g_clear_pointer (&cur->next, g_free);
         }
 
         if (!cur)
                 return;
 
         /*free the one remaining list */
-        if (cur->next) {
-                g_free (cur->next);
-                cur->next = NULL;
-        }
+        g_clear_pointer (&cur->next, g_free);
 
         g_free (cur);
         cur = NULL;
index 54f18f270c7521f2e1114e4a81fd8f355502db3c..ad800f93b746f1678faa087993dc65cfff128360 100644 (file)
@@ -1610,10 +1610,7 @@ cr_tknzr_new (CRInput * a_input)
         if (result->priv == NULL) {
                 cr_utils_trace_info ("Out of memory");
 
-                if (result) {
-                        g_free (result);
-                        result = NULL;
-                }
+                g_clear_pointer (&result, g_free);
 
                 return NULL;
         }